-
Notifications
You must be signed in to change notification settings - Fork 13.9k
coercions reviews/misc whatevers #147565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
coercions reviews/misc whatevers #147565
Conversation
This comment has been minimized.
This comment has been minimized.
70c3cf5 to
0d38d86
Compare
This comment has been minimized.
This comment has been minimized.
0d38d86 to
1375123
Compare
This comment has been minimized.
This comment has been minimized.
1375123 to
0b58522
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bce0933 to
eb6434f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e5524ca to
d8775a4
Compare
This comment has been minimized.
This comment has been minimized.
d8775a4 to
612a766
Compare
This comment has been minimized.
This comment has been minimized.
612a766 to
1184da6
Compare
This comment has been minimized.
This comment has been minimized.
797201d to
3ecd1a8
Compare
This comment has been minimized.
This comment has been minimized.
3ecd1a8 to
f23f16b
Compare
6179239 to
2958ef0
Compare
coercions reviews/misc whatevers
This comment has been minimized.
This comment has been minimized.
2369a79 to
2bf46ac
Compare
This comment has been minimized.
This comment has been minimized.
2bf46ac to
e227144
Compare
This comment has been minimized.
This comment has been minimized.
e227144 to
a409842
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (e0046e9): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 473.413s -> 474.101s (0.15%) |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
be7daf8 to
73228a9
Compare
This comment has been minimized.
This comment has been minimized.
73228a9 to
aa3959b
Compare
This comment has been minimized.
This comment has been minimized.
aa3959b to
644496d
Compare
This comment has been minimized.
This comment has been minimized.
We do this by: 1. Leak check for closure->fnptr coercions performed as part of a coerce-lub 2. Leak check closure<->fndef, fndef<->fndef and closure<->closure coercions to fnptrs 3. Leak check the fallback `lub` operation when a coerce-lub does not actually coerce note that fndef->fnptr and fnptr->fnptr coercions performed as part of a coerce-lub were already leak checked on stable and we continue to do so.
- leak checking the lub for fndef<->fndef coerce-lubs - start lubbing closure<->closure coerce-lubs and leak check it
644496d to
7b5f145
Compare
|
🎉 Experiment
Footnotes
|
"remove normalize call"
Fixes #132765 in theory breaking as we might now treat some previously-ambig hr aliases as rigid when we shouldn't. we may want to explicitly normalize the coercion target in
fcx.coercelike the new solver does."leak check and lub for closure<->closure coerce-lubs of same defids"
Fixes rust-lang/trait-system-refactor-initiative#233
the
|x| x + 1expr has a type ofClosure(?31t)which we wind up inferring the RPIT to. TheCoerceManyret_coercionfor the wholepeculiartypeck has an expected type ofRPIT(unnormalized). When we type check thereturn |x| x + 1expr we go from the never type toClosure(?31t)which then participates in theret_coerciongiving us acoerce-lub(RPIT, Closure(?31t)).Normalizing
RPITgives us someClosure(?50t)where?31tand?50thave been unified with?31tas the root var.resolve_vars_if_possibledoesn't resolve infer vars to their roots so these wind up with different structural identities so the fast path doesn't apply and we fall back to coercing to afnptr. cc #147193 which also fixes thisNew solver probably just gets more inference variables here because canonicalization + generally different approach to normalization of opaques. Idk :3
This technically allows more code to compile (see the test using TAIT in the commit). I don't think this can be observed on stable though.
In theory this could break existing code that relied on coercing a closure to itself resulting in a fnptr. I don't expect this to really happen in practice and this is an "obvious" bug fix.
leak check fndef<->fndef lubs of the same defids
when coerce-lub'ing a fndef with another fndef we already try to
lubit first to avoid coercing to a fnptr unnecessarily. we now leak check after thisluboperation.this avoids us incorrectly considering the fndefs to be equal despite unequal binders and then winding up with borrow checker errors due when coercing to a fnptr would have worked fine. see
tests/ui/coercion/leak_check_fndef_lub.rsthis is theoretically a breaking change as there could be dead code that relied on these unsatisfiable region constraints never being checked while also asserting that the output of the lub operation was an fndef. I don't think such code is likely to exist, and even if it does I am comfortable breaking it in favour of making code start working that expects us to coerce to a fnptr for unequal fndefs.
make coerce-lubs order independent
cc #73154 #97206
lubcurrently equates binders and then just returns the lhs without ever leak checking to ensure the binders are actually equal. this can lead to coerce-lub operations being order dependent, i.e. thata coerce-lub bhas differing behaviour tob coerce-lub a.we also cannot rely on borrow checking actually checking the constraints from equating the binders as
lubis a hir-typeck coercion concept that is not relevant once MIR has been built. In the MIR we can simply subtype all the types of match arms with the final type of the match.it is a forwards compatibility hazard to have coerce-lub be order dependent as it results in an effectively arbitrary inference choice which may or may not actually be correct or compatible with hypothetical future behaviours of
lubthat actually try to compute a proper lub'd type.on stable we attempt to make coerce-lubs order independent with two checks:
fndef->fnptrcoercionsfnptr->fnptrcoercionson stable we do this regardless of whether the coercion is occuring as part of a
coerce-lubor not.under this PR we have the following checks:
fnptr/fndef->fnptrcoercionsclosure->fnptrcoercions performed as part of a coerce-lubclosure/fndef<->closure/fndefcoerce-lubs that coerce both sides to fnptrsluboperation when a coerce-lub does not actually coercethis is theoretically breaking in two cases:
the second case actually is encountered by a few crates in practice which has been somewhat mitigated by the next change.
improving binder lub
this PR also implements a slight improvement to
luboperations on higher ranked types to avoid some regressions: #147565 (comment)when lubbing two higher ranked types, if one of the binders is empty then we now instantiate the other binder with inference variables and lub the instantiated type with the empty-binder type.
concretely:
for<'a> fn(&'a ()) lub fn(&'static ())fn(&'?a ()) lub fn(&'static ())'?a eq 'staticpasses leak checkwhereas the previous behaviour was:
for<'a> fn(&'a ()) lub fn(&'static ())fn(&'!a ()) eq fn(&'static ())'!a eq 'staticfails leak check"account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs"
We previously did not take safe target features into account when creating the fn sig for fndefs during
fndef<->closureorfndef<->fndefcoerce-lubs. We now do allowingcoerce-lubto produce a safe fn pointer when fndefs with safe target features are involved. This is consistent with existing (non lub) coercion logic forfndef->fnptrwhich allows coercing to a safe fn pointer.r? ghost